package com.wx.ssm.controller;

import com.wx.ssm.model.User;
import com.wx.ssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shkstart
 * @create 2020-05-07 17:34
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService ;

    @RequestMapping("/query")
    @ResponseBody
    @CrossOrigin
    public User queryUser(HttpServletRequest request, HttpServletResponse response, @RequestParam("id") int id) throws IOException {
        User user = userService.queryUsers(id);
        System.out.println(user);

        return user ;

    }


    @RequestMapping("/quser")
    public ModelAndView qUser(HttpServletRequest request, HttpServletResponse response, @RequestParam("id") int id) throws IOException {
        ModelAndView mv = new ModelAndView();
        User user = userService.queryUsers(id);
        System.out.println(user);

        mv.setViewName("user");
        mv.addObject("user",user);
        return mv ;

    }


    @RequestMapping("/addUser")
    public ModelAndView addUser(User user){

        ModelAndView mv = new ModelAndView() ;

        System.out.println(user.getUserName());

        mv.setViewName("success");
        return mv ;


    }




}
